#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e5+5;
int n;
int r[maxn];
priority_queue <int> q1;
struct DATA {
    int r, sum;
};
stack <DATA> q2;
void Push(int x) {
    if (q2.empty()) {
        q2.push(DATA{x, 1});
        return;
    }
    DATA t = q2.top();q2.pop();
    if (t.r == x) {
        t.sum++;
        q2.push(t);
    } else {
        q2.push(t);
        q2.push(DATA{x, 1});
    }
}
void Pop(int x) {
    if (q2.empty()) return;
    DATA t = q2.top();q2.pop();
    if (t.r > x) {
        t.sum--;
        if (t.sum > 0) q2.push(t);
    } else {
        if (q2.empty()) {
            q2.push(t);
            return;
        }
        DATA t2 = q2.top();q2.pop();
        t2.sum--;
        if (t2.sum > 0) q2.push(t2);
        q2.push(t);
    }
}

int main() {
    freopen("duel.in", "r", stdin);
    freopen("duel.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> r[i];
        q1.push(-r[i]);
    }
    while(!q1.empty()) {
        int t = q1.top();
        q1.pop();
        Pop(t);
        Push(t);
    }
    int ans = 0;
    while(!q2.empty()) {
        ans += q2.top().sum;q2.pop();
    }
    cout << ans << endl;
}
